using System;

namespace GraphSpace
{
	public class Graphgenerator<TV, TE> where TV : Knoten, new() where TE : Kante, new()
	{

		public Graphgenerator ()
		{
		}
		
		public static Graph<TV, TE> generiere_Zufall (int n, int m)
		{
			Graph<TV, TE> G = new Graph<TV, TE> ();
			for (int i = 0; i < n; i++)
			{
				G.neuerKnoten (i);
			}
			
			for(int i=0; i<m; i++)
			{
				bool gültig = false;
				while(!gültig)
				{
					Random zufall = new Random(i+System.DateTime.Now.Millisecond);
					int e1 = zufall.Next(0,n);
					int e2 = zufall.Next(0,n);
					if(G.neueKante(e1,e2,0.0))
						gültig = true;
				}
			}
			
			return G;
		}
		
		public static Graph<TV,TE> generiere_Eulerkreis(int n, int m)
		{
			// ToDo - prüfen, ob alle Knoten erreichbar
			Graph<TV, TE> G = new Graph<TV, TE> ();
			for(int i=0; i<n; i++)
				G.neuerKnoten(i);
			
			while(m > 0)
			{
				Random zufall = new Random(m + System.DateTime.Now.Millisecond);
				int s = zufall.Next(0, n);
				int x = s;
				int y;

				do
				{
					y = zufall.Next(0, n);
					if(y!=x)
					{
						G.neueKante(x, y, 0.0);
						m--;
						x = y;
					}
				}
				while(y != s);
			}
			
			return G;
		}
		
		public static Graph<TV, TE> generiere_Kreis(int n)
		{
			Graph<TV, TE> G = new Graph<TV, TE> ();
			for(int i=0; i<n; i++)
				G.neuerKnoten(i);
			for(int i=0; i<n-1; i++)
				G.neueKante(i, i+1, 0.0);
			G.neueKante(n-1, 0, 0.0);
			
			return G;
		}
	}
}
